package object3D;

import context.*;

import geometry3D.Point3D;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Line2D;
import java.awt.geom.GeneralPath;



// ***************************************************************************
// *** CLASS: Etage2Trapp
// ***************************************************************************
public class Etage2Trapp extends Block implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  public static final Color murFarge=Color.lightGray;

  public static final double oppTrinn=0.18;
  public static final double innTrinn=0.25;
  
  private boolean render2Etage=false;
  
  public Etage2Trapp(String ident,Point3D p0,double width,double height,double depth)
  { super(ident,p0,width,height,depth);
  }
  
  public void setRender2Etage()
  { render2Etage=true; }
    
  // ***************************************************************************
  // *** METHOD: getModel3D
  // ***************************************************************************
//  public /*abstract*/ Group getModel3D(Appearance appearance)
//  { Group tg=new Group();
//    tg.addChild(trinn1.getModel3D(appearance));
//    tg.addChild(trinn2.getModel3D(appearance));
//    tg.addChild(trinn3.getModel3D(appearance));
//    tg.addChild(trinn4.getModel3D(appearance));
//    tg.addChild(trinn5.getModel3D(appearance));
//    return(tg);
//  }  


  public void drawProjection(int direction,Graphics2D g,Point2D.Double origo2D,double scale,Color c)
  {

    Rectangle2D.Double r=projection(direction,origo2D,scale);
    switch(direction)
    {
      case NORTH: tegnTrapp(direction,g,r,origo2D,scale,c); break;
      case SOUTH: tegnTrapp(direction,g,r,origo2D,scale,c); break;
      case EAST: tegnTrapp(direction,g,r,origo2D,scale,c); break;
      case WEST: tegnTrapp(direction,g,r,origo2D,scale,c); break;
//      case ABOVE: drawProjectionAbove(g,r,scale,c); break;
//      case BELOW: drawProjectionBelow(g,r,scale,c); break;
//      case VCUT: drawVerticalCut(g,r,scale,c); break;
      case HCUT: tegnTrappPlan(g,r,origo2D,scale,c); break;
      default: super.drawProjection(direction,g,origo2D,scale,c);
    }  
  }

  private void tegnTrapp(int direction,Graphics2D g,Rectangle2D.Double r,Point2D.Double origo2D,double scale,Color c)
  {
  }

  private void tegnTrappPlan(Graphics2D g,Rectangle2D.Double r,Point2D.Double origo2D,double scale,Color c)
  {
    double yn=r.y;
    double n1=r.x;
    double n2=n1+0.40*scale;
    double n3=n2+0.40*scale;
    double n4=n3+0.40*scale;
    double n5=n4+0.40*scale;
    double n6=n5+0.40*scale;
    
    double xe=r.x+r.width;
    double e1=r.y+0.40*scale;
    double e2=e1+0.40*scale;
    double e3=e2+0.40*scale;
    double e4=e3+0.30*scale;
    double e5=e4+0.30*scale;
    
    double ss=r.x+0.60*scale;
    
    double ys=r.y+1.0*scale;
    double s1=ss;
    double s2=s1+0.10*scale;
    double s3=s2+0.20*scale;
    double s4=s3+0.20*scale;
    double s5=s4+0.15*scale;
    double s6=s5+0.10*scale;

    double xv=ss+0.80*scale;
    double v1=ys+0.05*scale;
    double v2=v1+0.10*scale;
    double v3=v2+0.15*scale;
    double v4=v3+0.20*scale;
    double v5=v4+0.30*scale;
    
    if(!render2Etage)
    { line(g,n1,yn,s1,ys);
      line(g,n2,yn,s2,ys);
    }
    line(g,n3,yn,s3,ys);
    line(g,n4,yn,s4,ys);
    line(g,n5,yn,s5,ys);
    line(g,n6,yn,s6,ys);
    line(g,xe,e1,xv,v1);
    line(g,xe,e2,xv,v2);
    line(g,xe,e3,xv,v3);
    line(g,xe,e4,xv,v4);
    line(g,xe,e5,xv,v5);
    
    // Tegn Rekkverk
    Rectangle2D.Double rekkverk1;
    if(render2Etage) rekkverk1=new Rectangle2D.Double(ss+0.20*scale,ys,(0.80-0.20)*scale,0.05*scale);
    else             rekkverk1=new Rectangle2D.Double(ss,ys,0.80*scale,0.05*scale);
    g.draw(rekkverk1);
//    Rectangle2D.Double rekkverk2=new Rectangle2D.Double(ss+0.75*scale,ys,0.05*scale,0.90*scale);
    Rectangle2D.Double rekkverk2=new Rectangle2D.Double(xv-0.05*scale,ys,0.05*scale,0.90*scale);
    g.draw(rekkverk2);
    
    // Tegn Pil
    double x0=r.x+0.90*scale;
    double y0=r.y+0.425*scale;
    double xT=x0+0.80*scale;
    double dx=0.20*scale;
    double dy=0.15*scale;    
    line(g,x0,y0,xT,y0);
    line(g,xT,y0,xT-dx,y0+dy);
    line(g,xT,y0,xT-dx,y0-dy);
  }
  
  
  private void line(Graphics2D g,double x1,double y1,double x2,double y2)
  { g.draw(new Line2D.Double(x1,y1,x2,y2)); }

}
